home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / T U R B O Language / Turbo C v2.0 / HELPME!.DOC < prev    next >
Text File  |  1988-08-29  |  18KB  |  479 lines

  1.               TURBO C 2.0: ANSWERS TO COMMON QUESTIONS
  2.  
  3.  
  4.  G e t t i n g     S t a r t e d
  5.  ----------------------------------------------------------------------
  6.  Q. How do I install Turbo C?
  7.  A. Run the INSTALL program from the INSTALL/HELP disk. To start
  8.     the installation, change your current drive to the one that
  9.     has the install program on it and type INSTALL. You will be
  10.     given instructions in a box at the bottom of the screen for
  11.     each prompt. For example, if you will be installing from
  12.     drive A:, type:
  13.  
  14.     A:
  15.     INSTALL
  16.  
  17.     At this point, the INSTALL program will appear with menus
  18.     selections and descriptions to guide you through the installation
  19.     process.
  20.  
  21.  Q. How do I run Turbo C?
  22.  A. After you have installed Turbo C, type "TC" from the DOS
  23.     prompt and you're ready to go. Chapter 2 (Getting Started)
  24.     of the Turbo C User's Guide will guide you through your
  25.     first Turbo C program.
  26.  
  27.  Q. What is the difference between TC.EXE and TCC.EXE?
  28.  A. The Turbo C package comes with two compilers, an Integrated
  29.     Environment named TC.EXE and a command-line compiler named
  30.     TCC.EXE. The Integrated Environment is essentially
  31.     the command-line compiler with an integrated editor,
  32.     linker, and debugger. Please refer to the Turbo C
  33.     User's Guide for details on using both systems.
  34.  
  35.  Q. What is a configuration file?
  36.  A. A configuration file tells Turbo C what options to default to
  37.     and where to look for its library and header files. TC.EXE
  38.     looks for a configuration file named TCCONFIG.TC, and
  39.     TCC.EXE looks for a file named TURBOC.CFG. See the User's
  40.     Guide, pages 40 and 143 for more information.
  41.  
  42.  Q. How do I create a configuration file?
  43.  A. When you run the INSTALL program it creates a configuration
  44.     file named TURBOC.CFG for TCC.EXE. This file is just an
  45.     ASCII file which you can change with any text editor. It
  46.     contains the path information for the library and header
  47.     files for TCC.EXE to use. The INSTALL program does not
  48.     create a TCCONFIG.TC file for TC.EXE because it installs
  49.     the directory information directly into TC.EXE. You can
  50.     create a configuration file for TC.EXE by running TC,
  51.     setting your options however you want to set them, and
  52.     typing Alt-O/S.
  53.  
  54.  I n t e g r a t e d    E n v i r o n m e n t
  55.  ----------------------------------------------------------------------
  56.  Q. Why is Turbo C not able to find any of my #include files?
  57.  A. The compiler searches for include files in the Turbo C Include
  58.     Directories. This option is specified under the Options/Directories
  59.     menu. The INSTALL program initially sets this option to the
  60.     directory where it copied all the Turbo C *.h files.
  61.  
  62.  
  63.  Q. Why do I get the message:
  64.     Linker Error: Unable to open input file 'C0x.OBJ'
  65.  A. The linker searches for Turbo C start-up and library files in the
  66.     Turbo C Library Directories. This option is specified under the
  67.     Options/Directories menu. The INSTALL program initially sets this
  68.     option to a directory where it copied the start-up and library
  69.     files.
  70.  
  71.  
  72.  Q. How do I get Turbo C to link in my own libraries or use multiple
  73.     source files?
  74.  A. Turbo C's Project facility is designed to allow you to work with
  75.     multiple files. Refer to Chapter 3 of the Turbo C User's Guide,
  76.     under "Projects: Using Multiple Source Programs".
  77.  
  78.  
  79.  Q. Why does the linker tell me that all the graphics library
  80.     routines are undefined?
  81.  A. The Options/Linker/Graphics Library item must be set ON, if
  82.     you are using any Turbo C graphics functions and have not
  83.     specifyed GRAPHICS.LIB in a project file.
  84.  
  85.  
  86.  Q. Why does Turbo C report "Unable to open include file 'stdarg.h'"
  87.     when I try to #include <stdio.h>?
  88.  A. The most probable reason is that you have exceeded the number
  89.     of files that DOS can have open simultaneously.  Add the line
  90.  
  91.         FILES=20
  92.  
  93.     to your DOS CONFIG.SYS file. This allows DOS to open up to 20
  94.     files at the same time. CONFIG.SYS will only be effective
  95.     after you have rebooted your computer. See the IBM DOS Reference
  96.     Manual for details on the CONFIG.SYS file.
  97.  
  98.  
  99.  Q. How do I change the colors of the editor and menus in TC?
  100.  A. The utility TCINST.EXE allows you to customize your colors.
  101.  
  102.  
  103.  Q. How do I get a listing of my source code to my printer?
  104.  A. From within the Turbo C editor hit <Ctrl><K><P>. This will
  105.     print a marked block to the printer. If no block is marked
  106.     this key sequence will print the entire file in your editor.
  107.  
  108.  
  109.  Q. When I Make, Run, or Trace a program Turbo C sometimes goes
  110.     through the compile and link process even when the object files
  111.     are up-to-date.
  112.  A. Turbo C's MAKE logic works solely on a file's date and time
  113.     stamp. If one of your source files is marked with a date
  114.     that's sometime in the future, the object files that are
  115.     created from it will always be older than the source file,
  116.     and Turbo C will always try to rebuild the file. You can fix
  117.     this by using TOUCH.COM to set the file to the current date
  118.     and time. You should also make sure that your system's date
  119.     and time are always properly set.
  120.  
  121.  
  122.  C o m m a n d  -  L i n e    C o m p i l e r
  123.  ----------------------------------------------------------------------
  124.  Q. Why is Turbo C not able to find any of my #include files?
  125.  A. The compiler searches for include files in the Turbo C Include
  126.     Directories. This option is specified by the -I switch. The INSTALL
  127.     program initially writes a configuration file (TURBOC.CFG) that
  128.     sets this to the directory where it copied all the Turbo C *.h
  129.     files.
  130.  
  131.  
  132.  Q. Why do I get the message:
  133.     Linker Error: Unable to open input file 'C0x.OBJ'
  134.  A. The linker searches for Turbo C start-up and library files in the
  135.     Turbo C Library Directories. This option is specified by the -L
  136.     switch. If you allow TCC to invoke the linker, it will search the
  137.     directories in the configuration file (TURBOC.CFG) written by the
  138.     INSTALL program. If you run TLINK, the configuration file is not read.
  139.  
  140.  Q. Why does the linker tell me that all the graphics library
  141.     routines are undefined?
  142.  A. TCC will not search the graphics library unless you tell it to.
  143.     You should specify the graphics library on the command line. For
  144.     example, to compile BGIDEMO, type
  145.  
  146.         TCC BGIDEMO.C GRAPHICS.LIB<Enter>
  147.  
  148.  
  149.  G e n e r a l     I / O
  150.  ----------------------------------------------------------------------
  151.  Q. The '\n' in cprintf() does not return the cursor to the
  152.     beginning of the line. It only moves the cursor down one line.
  153.  A. cprintf() no longer interprets '\n' as a Carriage Return/
  154.     Line Feed combination. The '\n' only outputs a Line Feed. To
  155.     force the cursor to the beginning of the line, manually
  156.     insert a Carriage Return:
  157.  
  158.       cprintf("\n\r");
  159.  
  160.  
  161.  Q. How do I print to the printer from a Turbo C program?
  162.  A. Turbo C uses a FILE pointer (stdprn) defined in the STDIO.H
  163.     file. You do not need to open stdprn before using it:
  164.  
  165.     #include <stdio.h>
  166.     main()
  167.     {
  168.         fprintf(stdprn, "Hello, world\n");
  169.     }
  170.  
  171.     Note that if your printer is line-buffered, the output is
  172.     flushed only after a '\n' is sent.
  173.  
  174.  
  175.  Q. I am reading and writing binary files. My program is
  176.     translating the Carriage Return (0x0D) and Line Feed (0x0A)
  177.     characters. How do I prevent this from happening?
  178.  A. Files opened in text mode will translate these characters for
  179.     DOS. To read a file in binary mode, open it in binary mode.
  180.     For example
  181.  
  182.       #include <stdio.h>
  183.       main()
  184.       {
  185.          FILE *binary_fp;
  186.          char buffer[100];
  187.  
  188.          binary_fp = fopen("MYFILE.BIN", "rb");
  189.  
  190.          fread(buffer, sizeof(char), 100, binary_fp);
  191.  
  192.                     :
  193.       }
  194.  
  195.     The default file mode is text.
  196.  
  197.  
  198.  Q. Why don't printf() and puts() print text in color?
  199.  A. Use the console I/O functions cprintf() and cputs() for color output.
  200.  
  201.       #include <conio.h>
  202.       main()
  203.       {
  204.           textcolor(BLUE);
  205.           cprintf("I'm blue.");
  206.       }
  207.  
  208.  
  209.  Q. How do I print a long integer?
  210.  A. Use the "%ld" format:
  211.  
  212.       long int l = 70000L;
  213.       printf("%ld", l);
  214.  
  215.  
  216.  Q. How do I print a long double?
  217.  A. Use the "%Lf" format.
  218.  
  219.       long double ldbl = 1E500;
  220.       printf("%Lf", ldbl);
  221.  
  222.  
  223.  E x a m p l e   P r o g r a m s
  224.  ----------------------------------------------------------------------
  225.  Q. How do I compile the MICROCALC spread sheet?
  226.  A. See Appendix G of the Turbo C Reference Manual.
  227.  
  228.  
  229.  Q. How do I compile the BGIDEMO program?
  230.  A. 1. Make sure that the following Turbo C files are in your
  231.        current directory:
  232.  
  233.          BGIDEMO.C
  234.          *.BGI
  235.          *.CHR
  236.  
  237.     2. Run TC.
  238.  
  239.     3. Load BGIDEMO.C into the Editor by hitting F3 then typing
  240.        BGIDEMO<Enter>
  241.  
  242.     3. Go to the Run menu and choose the Run item.
  243.  
  244.  
  245.  Q. How do I create a COM file?
  246.  A. DOS versions 3.2 and earlier include an EXE2BIN utility that
  247.     converts EXE files to COM files. For users who do not have
  248.     EXE2BIN, the Turbo C command-line linker, TLINK will create
  249.     a COM file instead of an EXE file if the /t option is
  250.     specified. For example:
  251.  
  252.      tcc -mt -lt tiny
  253.  
  254.     will create TINY.COM instead of TINY.EXE.
  255.  
  256.     There are certain limitations in converting an EXE file to a COM
  257.     file. These limitations are documented in the IBM Disk Operating
  258.     System manual under EXE2BIN.
  259.  
  260.     Turbo C's TINY model is compatible with the COM format, but programs
  261.     that use Turbo C's floating point routines cannot be converted to a
  262.     COM file.
  263.  
  264.  
  265.  G r a p h i c s
  266.  ----------------------------------------------------------------------
  267.  Q. Why do I get the error message:
  268.  
  269.        BGI Error: graphics not initialized (use 'initgraph')
  270.  
  271.     when I use a graphics function? My program has already
  272.     called initgraph().
  273.  A. For some reason initgraph() failed. To find out why, check
  274.     the return value of graphresult(). For example:
  275.  
  276.       #include <graphics.h>
  277.       main()
  278.       {
  279.         int gerr;   /* graphics error */
  280.         int gdriver = DETECT, gmode;
  281.  
  282.         /* Initialize graphics using auto-detection and look
  283.            for the .BGI and .CHR files in the C:\TURBOC directory.
  284.         */
  285.         initgraph(&gdriver, &gmode, "C:\\TURBOC");
  286.  
  287.         if ((gerr = graphresult()) != grOk)
  288.         {
  289.             printf("Error : %s\n", grapherrormsg(gerr));
  290.             exit(1);
  291.         }
  292.  
  293.                :
  294.       }
  295.  
  296.  
  297.  M a t h  /  F l o a t i n g    P o i n t
  298.  ----------------------------------------------------------------------
  299.  Q. Why do I get incorrect results from all the math library
  300.     functions like cos() and tan()?
  301.  A. You must #include <math.h> before you call any of the standard
  302.     Turbo C math functions. In general, Turbo C assumes that a function
  303.     that is not declared returns an int. In the case of math functions,
  304.     they usually return a double. For example
  305.  
  306.         /* WRONG */                       /* RIGHT */
  307.                                           #include <math.h>
  308.         main()                            main()
  309.         {                                 {
  310.           printf("%f", cos(0));             printf("%f", cos(0));
  311.         }                                 }
  312.  
  313.  
  314.  Q. How do I "trap" a floating point error?
  315.  A. See the signal() and matherr() functions in the Turbo C Reference
  316.     Guide.  The signal() function may be used to trap errors in the
  317.     80x87 or the 80x87 emulator. The matherr() function traps errors
  318.     in the Math Library functions.
  319.  
  320.  
  321.  L i n k e r    E r r o r s
  322.  ----------------------------------------------------------------------
  323.  Q. Why do I get the message:
  324.       Linker Error: Unable to open input file 'C0x.OBJ'
  325.  A. See "Integrated Environment" section above.
  326.  
  327.  
  328.  Q. Why do I get the message:
  329.       Linker Error: Undefined symbol '_main' in module C0
  330.  A. Every C program must contain a function called main(). This
  331.     is the first function executed in your program. The function
  332.     name must be all in lower case. If your program does not
  333.     have one, create one. If you are using multiple source files,
  334.     the file that contains the function main() must be one of
  335.     the files listed in the Project.
  336.  
  337.     Note that an underscore character '_' is prepended to all
  338.     external Turbo C symbols.
  339.  
  340.  
  341.  Q. Why does the linker tell me that all the graphics library
  342.     routines are undefined?
  343.  A. See the "Integrated Environment" and "Command-line Compiler"
  344.     sections above.
  345.  
  346.  
  347.  Q. What is a 'Fixup overflow'?
  348.  A. See the listing of TLINK error messages in Appendix D of the
  349.     Turbo C Reference Guide.
  350.  
  351.  
  352.  Q. I am linking my own assembly language functions with Turbo C.
  353.     The linker reports that all of my functions are undefined.
  354.  A. Make sure that you have put an underbar character '_' in front of all
  355.     assembly language function names to be called by Turbo C. Your assembly
  356.     language program should be assembled with Case Sensitivity. See
  357.     the Chapter 12, "Advanced Programming," in the Turbo C User's Guide
  358.     for details.
  359.  
  360.  
  361.  O t h e r    Q u e s t i o n s
  362.  ----------------------------------------------------------------------
  363.  Q. How do I change the stack size?
  364.  A. The size of the stack of a Turbo C program is determined at
  365.     run-time by the global variable _stklen. To change the size
  366.     to, for example 10000 bytes, include the following line in
  367.     your program:
  368.  
  369.       extern unsigned _stklen = 10000;
  370.  
  371.     This statement must not be inside any function definition.
  372.     The default stack size is 4096 bytes (4K).
  373.  
  374.  Q. I'm getting a 'Stack Overflow!' message when I run my program.
  375.     How can I work around this?
  376.  A. You may increase the stack size by following the procedure above. Stack
  377.     overflows are usually caused by a large amount of local data or
  378.     recursive functions. You can decrease the amount of stack space
  379.     used by declaring your local variables static:
  380.  
  381.          main()                        main()
  382.          {                             {
  383.              char x[5000];     -->          static char x[5000];
  384.                  :                                :
  385.          }                             }
  386.  
  387.     Of course, you should be aware that there are other effects
  388.     that the "static" keyword has, as applied here.
  389.  
  390.  Q. My program comes up with the message 'Null pointer assignment'
  391.     after it terminates. What does this mean?
  392.  A. Before a small-data model Turbo C program returns to DOS, it will
  393.     check to see if the beginning of its data segment has been corrupted.
  394.     This message is to warn you that you have used uninitialized pointers
  395.     or that your program has corrupted memory in some other way.
  396.  
  397.  Q. Why are .EXE files generated by TC.EXE larger than those
  398.     generated by TCC.EXE?
  399.  A. In the default configuration, TC.EXE includes debugging
  400.     information in the .EXE files that it creates, and TCC.EXE
  401.     does not. If you don't want to produce this debugging
  402.     information, you can shut it off in the Integrated
  403.     Development Environment by selecting Alt-D/S/N.
  404.  
  405.  
  406.  Q. Why do I get "declaration syntax error" messages on DOS.H?
  407.  A. You have set the "Ansi keywords only" option ON. Keep this option
  408.     OFF when using any keywords specific to Turbo C .
  409.  
  410.  
  411.  Q. I have a working program that dynamically allocates memory
  412.     using malloc() or calloc() in small data models (tiny, small,
  413.     and medium).  When I compile this program in large data models
  414.     (compact, large, and huge) my program hangs.
  415.  A. Make sure that you have #include <alloc.h> in your program.
  416.  
  417.  
  418.  Q. I am linking my own assembly language functions with Turbo C.
  419.     But the linker reports that all of my functions are undefined.
  420.  A. See answer above in the "Linker" section.
  421.  
  422.  
  423.  Q. My far pointers "wrap around" when they are incremented over 64K.
  424.     How do I reference a data object that is greater than 64K?
  425.  A. Use huge pointers.
  426.  
  427.  
  428.  Q. Can I declare more than 64K of global variables?
  429.  A. You may have a total of up to 64K global and static data in
  430.     the Tiny, Small, Medium, Compact and Large memory models. In
  431.     the Huge model, the maximum is 64K per source module.
  432.  
  433.  
  434.  Q. How do I declare an array that's greater than 64K?
  435.  A. Arrays greater than 64K must be allocated off the heap. If,
  436.     for example you wanted a two-dimensional array of characters
  437.     that was 1024 by 128, the declaration you would expect to
  438.     write would be:
  439.  
  440.        char array[1024][128];
  441.  
  442.     But since the size of this array is greater than 64K, it must
  443.     be allocated off the heap. An example of this is:
  444.  
  445.       #include <alloc.h>
  446.  
  447.       char (huge *array)[128];
  448.             :
  449.       main()
  450.        {
  451.             :
  452.           array = farcalloc(sizeof(*array), 1024);
  453.             :
  454.        }
  455.  
  456.     The array can be accessed with the same code as an array not
  457.     allocated off the heap. For example:
  458.  
  459.     i = array[30][56];
  460.  
  461.     will assign "i" the value stored at the 31st by 57th element
  462.     in "array".
  463.  
  464.     The use of the "huge" keyword is necessary in the declaration
  465.     of "array" since only a huge pointer can address objects
  466.     greater than 64k. For further discussion of huge pointers,
  467.     refer to the User's Guide.
  468.  
  469.  
  470.  Q. How do I interface Turbo C routines to a Turbo Pascal program?
  471.  A. See the example programs CPASDEMO.PAS and CPASDEMO.C on disk.
  472.     These files are packed in the file EXAMPLES.ARC and you will
  473.     need to UNPACK them before using them.
  474.  
  475.  
  476.  Q. How do I get Clipper to link with Turbo C?
  477.  A. If you are having trouble, contact Nantucket Technical Support.
  478.  
  479.